﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace 初识日志
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ServiceCollection services = new ServiceCollection();

            services.AddLogging(logBuilder =>
            {                
                logBuilder.AddConsole();    //输出日志到控制台
                //logBuilder.AddEventLog();   //输出日志到Windows EventLog（事件查看器）

                //日志级别：Trace<Debug<Information<Warning<Error<Critical
                //如果不设置，那么默认只输出 warning 及以上的日志
                logBuilder.SetMinimumLevel(LogLevel.Debug); //设置日志输出的最低级别
            }
            );

            services.AddScoped<Log>();

            using (var sp = services.BuildServiceProvider())
            {
                var log = sp.GetService<Log>();
                log.LogPrint();
            }
        }
    }
}
